# import requests
# import json
# import asyncio
# import aiohttp

# url = 'https://api.web.360kan.com/v1/rank?cat=6'
#
#
# res = requests.get(url)
# text = res.text[len('__jp0('):-2]
# print(json.dumps(json.loads(text),indent=4,ensure_ascii=False))

# async def fetch(session,url):
# 	async with session.get(url) as response:
# 		text = await response.json()
# 		return text
#
# async def main():
# 	async with aiohttp.ClientSession() as session:
# 		r = await asyncio.gather(*[fetch(session,f'https://api.web.360kan.com/v1/rank?cat={i}') for i in range(1,7)])
# 		for j in r:
# 			print(j)
#
#
# asyncio.run(main())


# 多线程

import requests
import threading

def fetch(url):
	res = requests.get(url)
	text = res.json()
	print( f'线程{threading.current_thread().name} 获取: {url} 响应: {text}')


def main():
	urls = [f'https://api.web.360kan.com/v1/rank?cat={i}' for i in range(1, 7)]
	threads = []  # 保存线程对象
	
	# 创建并启动所有线程
	for url in urls:
		# 正确写法：target传入函数名，args传入参数
		t = threading.Thread(target=fetch, args=(url,))
		threads.append(t)
		t.start()
		print(f"启动线程获取: {url}")
	
	# 等待所有线程完成
	for i, thread in enumerate(threads):
		thread.join()
		print(f"线程 {i + 1} 已完成")
	
	print("所有线程执行完毕")
		


if __name__ == '__main__':
	main()
